import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate';

Vue.use(Vuex);

const store = new Vuex.Store({
  // 注册
  plugins: [createPersistedState()],
  state: {
    username: '',
    token: '',
    refreshToken: '',
  },
  mutations: {
    addToken(state, token) {
      state.token = token;
    },
    addRefreshToken(state, refreshToken) {
      state.refreshToken = refreshToken;
    },
    addUser(state, username) {
      state.username = username;
    },
    delUser(state) {
      state.username = '';
    },
    delToken(state) {
      state.token = '';
    },
  },
});
export default store;
